package com.jt.assistant.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.jt.assistant.R
import com.jt.assistant.bean.ScanCarton
import com.jt.assistant.bean.ScanDataBean
import com.jt.assistant.bean.Waybill

class WaybillListAdapter(mData: MutableList<Waybill>) :
    BaseQuickAdapter<Waybill, BaseViewHolder>(
        R.layout.item_scan_waybill, mData
    ) {


    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: Waybill) {
        val tvCode = holder.getView<TextView>(R.id.tv_Code)
        val tvNum = holder.getView<TextView>(R.id.tv_Num)
        val tvStatus = holder.getView<TextView>(R.id.tv_status)
        var hasScan = 0
        var totalScan = 0
        if (mScanCartonList != null) {

            mScanCartonList!!.forEach {
                if (item.channelOrderNo == it.channelOrderNo) {
                    totalScan++
                    if (it.hasScan) {
                        hasScan++
                    }
                }
            }

            tvCode.text = item.channelOrderNo
            tvNum.text = "$hasScan/$totalScan"

            when (hasScan) {
                0 -> {//未扫码
                    tvCode.setTextColor(Color.RED)
                    tvNum.setTextColor(Color.RED)
                    tvStatus.setTextColor(Color.RED)
                    tvStatus.text = "扫码未开始"
                }
                totalScan -> {//扫码已完成
                    tvCode.setTextColor(Color.LTGRAY)
                    tvNum.setTextColor(Color.LTGRAY)
                    tvStatus.setTextColor(Color.LTGRAY)
                    tvStatus.text = "扫码已完成"
                }
                else -> {//扫码进行中
                    tvCode.setTextColor(Color.BLUE)
                    tvNum.setTextColor(Color.BLUE)
                    tvStatus.setTextColor(Color.BLUE)
                    tvStatus.text = "扫码进行中"
                }
            }
        }
    }

    private var mScanCartonList: List<ScanCarton>? = null
    fun updateData(scanData: ScanDataBean, scanCartonList: List<ScanCarton>) {
        data.addAll(scanData.waybillList)
        mScanCartonList = scanCartonList
        notifyDataSetChanged()
    }


}